

import os
from ament_index_python import get_package_prefix
from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import ExecuteProcess
from launch_ros.actions import Node


from launch.actions import SetEnvironmentVariable
gazebo_env = SetEnvironmentVariable("GAZEBO_MODEL_PATH", os.path.join(get_package_prefix("mooncar"), "share"))

# 获取包的共享目录
mooncar_share_dir = get_package_share_directory('mooncar')

# 构造urdf文件的完整路径
urdf_model_path = os.path.join(mooncar_share_dir, 'urdf')




def generate_launch_description():
    return LaunchDescription([
        ExecuteProcess(
        cmd=['gazebo', '--verbose','-s', 'libgazebo_ros_init.so', '-s', 'libgazebo_ros_factory.so'],
        output='screen'),

        # ExecuteProcess(
        #     cmd=['xacro', urdf_model_path + '/mooncar.urdf.xacro', '-o', urdf_model_path + '/mooncar.urdf'],
        #     output='screen'
        # ),

        Node(
            package='gazebo_ros', 
            executable='spawn_entity.py',
            arguments=['-entity', "mooncar", '-file', urdf_model_path + '/mooncar.urdf'],
            output='screen'
        ),
    ])
